package org.example.ssh

import com.alibaba.fastjson2.JSON
import com.alibaba.fastjson2.JSONB
import net.schmizz.sshj.SSHClient
import org.example.ssh.base.SSH
import org.example.ssh.base.SshCtx
import org.example.ssh.base.executeCmdPrint
import org.example.ssh.base.uploadDirectoryRecursive
import test.t1.TurnCredentialGenerator

// coturn 一个机器只能启动一个实例，因为端口多
suspend fun main() {
//    val list = SSH.getGroup("dev_coturn-HK-2")
//    SSH.execF(list) {
//        DeployCoturn().deploy(it)
//    }

    val strings =
        TurnCredentialGenerator.generateCredentials("zjn", 3600, "cdb5e2fc-9c5e-4d3a-92bd-55fd681298f4")
    println(JSON.toJSONString(strings))
    //["1758183968:zjn","glKsvCOUxorxkmzzfmXXCPj+eFc="]
}

/**
 * 测试
https://webrtc.github.io/samples/src/content/peerconnection/trickle-ice/
stun:38.147.171.207:33478
1758183968:zjn
glKsvCOUxorxkmzzfmXXCPj+eFc=
 */
class DeployCoturn {

    suspend fun deploy(sshCtx: SshCtx) {
//        executeCmdPrint(sshCtx.cli, "cd /home/${sshCtx.cName} && docker-compose logs ${sshCtx.cName}")
//        executeCmdPrint(sshCtx.cli, "docker ps")
//        executeCmdPrint(sshCtx.cli, "cd /home/${sshCtx.cName} && docker-compose -f docker-compose.yml down")

//        executeCmdPrint(sshCtx.cli, "docker exec dev_coturn-HK-2 ls -la /var/log/turnserver ")

//        val sftp = sshCtx.cli.newSFTPClient()
//        uploadDirectoryRecursive(sftp, "./配置/coturn/${sshCtx.cName}", "/home")

//        executeCmdPrint(sshCtx.cli, "cd /home/${sshCtx.cName} && docker-compose -f docker-compose.yml up -d")

//        sftp.get("/home/${sshCtx.cName}/turn.log", "C:\\Users\\pc\\Downloads\\turn.log")
    }

}










